//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef __MESH_SWITCH_DIE_H_
#define __MESH_SWITCH_DIE_H_

#define NORTH 0
#define SOUTH 1
#define WEST 2
#define EAST 3

#include <omnetpp.h>
#include "packet_m.h"
#include <vector>
#include <string>
#include <cstring>
#include "packet_m.h"

using namespace omnetpp;

/**
 * TODO - Generated class
 */
class Die : public cSimpleModule
{
public:
    // 构造函数和析构函数
    Die();
    virtual ~Die();
protected:
    virtual void initialize() override;
    virtual void handleMessage(cMessage *msg) override;
    // 计算路由并进行包的转发
    virtual int routeMessage(Packet *packet_tobesent);
    // 更新显示数据
    virtual void refreshDisplay() const override;

    // 定义每个端口的队列
    //std::vector<cQueue> every_queue;
    // voq
    std::vector<std::vector<cQueue>> every_queue;
    // 处理一个bit所消耗的时间
    double DELAY;

    // 用于队列管理
    // endServiceMsg是self message
    std::vector<cMessage *> endServiceMsg;
    std::vector<cMessage *> endServiceMsg1;
    std::vector<cMessage *> endServiceMsg2;
    std::vector<cMessage *> endServiceMsg3;
    // 指针：用于标记正在服务的包
    std::vector<Packet *> msgServiced;
    std::vector<Packet *> msgServiced1;
    std::vector<Packet *> msgServiced2;
    std::vector<Packet *> msgServiced3;

    // 用于队列利用率统计
    simsignal_t percentageSingal;
    std::vector<double> every_queue_percent;
    double sum;
};

#endif
